﻿<%@ Application Language="C#" %>

<script runat="server">

    void Application_Start(object sender, EventArgs e) 
    {
        // Code that runs on application startup
         
        DateTime now = DateTime.Now;
        TimeSpan ts = DateTime.Parse(now.AddDays(1).ToString("yyyy-MM-dd")) - now;
        System.Timers.Timer myTimer = new System.Timers.Timer(ts.TotalMilliseconds);
        myTimer.Elapsed += new System.Timers.ElapsedEventHandler(OnTimedEvent);
        myTimer.Enabled = true;
        
        Permission p = new Permission();
        p.IsCompanyEdit = true;
        
        CompanyBLL bll = new CompanyBLL(p);
        
        InternalManagementSystem.DAO.Models.Company pCompany = new InternalManagementSystem.DAO.Models.Company();
        pCompany.CompanyName = System.Configuration.ConfigurationManager.AppSettings["maincompany"];
        pCompany.Address = pCompany.CompanyName;
        pCompany.StatisticalEndDate = DateTime.Now;
        pCompany.StatisticalStartDate = DateTime.Now;
        pCompany.IsAutoRecharge = 0;
        pCompany.GuardLine = 0; 
        bll.AddCompany(pCompany);

    }

    private void OnTimedEvent(object source, System.Timers.ElapsedEventArgs e)
    {
        InternalManagementSystem.DAO.DBHelper helper = new InternalManagementSystem.DAO.DBHelper();
        helper.ExecuteNonQuerySQL("exec [windb].[dbo].[RechargeIntegral]");
        helper.ExecuteNonQuerySQL("exec [windb].[dbo].[AutoDeductIntegral]");
    }

    
    void Application_End(object sender, EventArgs e) 
    {
        //  Code that runs on application shutdown

    }
        
    void Application_Error(object sender, EventArgs e) 
    { 
        // Code that runs when an unhandled error occurs

    }

    void Session_Start(object sender, EventArgs e) 
    {
        // Code that runs when a new session is started

    }

    void Session_End(object sender, EventArgs e) 
    {
        // Code that runs when a session ends. 
        // Note: The Session_End event is raised only when the sessionstate mode
        // is set to InProc in the Web.config file. If session mode is set to StateServer 
        // or SQLServer, the event is not raised.

    }
       
</script>
